#-*- coding: utf8 -*-
from tutor.script import *
from tutor.plugin.maple import *

# variáveis úteis
half = M('1/2')
t = M.t
_i, _j, _k = M('_i, _j, _k')
rr = M('`..`')

# parâmetros iniciais
a, lambd = map(M, oneof(
    (2, 3*half),
    (1, 2),
    (half, 3*half),
    (2, 2)
))
t0, t1 = oneof(
    (M.Pi/4, M.Pi),
    (0, 3*M.Pi/4),
    (0, M.Pi/4),
    (M.Pi/4, M.Pi/2),
)

# funções relacionadas ao caminho
X = a * cos(t)
Y = a * sin(t)
Vx, Vy = ( M.diff(f, t) for f in [X, Y] )
v = M.simplify(M.sqrt(Vx**2 + Vy**2))
m = M.int(v * lambd, t=rr(t0, t1))
print('variáveis: \n\tR=(%s, %s)\n\tV=(%s, %s)\n\tt0=%s, t1=%s' 
       % (X, Y, Vx, Vy, t0, t1))

# xcm
xcm = M.simplify(M.int(v * lambd * X, t=rr(t0, t1)) / m)
print('xcm: %s' % xcm)

# ycm
ycm = M.simplify(M.int(v * lambd * Y, t=rr(t0, t1)) / m)
print('ycm: %s' % ycm)

# esqueceu de dividir pela massa
xcmNMass = M.expand(xcm * m)
ycmNMass = M.expand(ycm * m)

# esqueceu lambda e massa
err1 = M.int(v * X, t=rr(t0, t1))
err2 = M.int(v * Y, t=rr(t0, t1))
